//
//  ZHAnchorDetailTableViewCell.m
//  XMLYFM
//
//  Created by dllo on 15/12/24.
//  Copyright © 2015年 zzl. All rights reserved.
//

#import "ZHAnchorDetailTableViewCell.h"
#import "BaseLabel.h"
#import "AppTools.h"
#import "Masonry.h"
#import "UIImageView+Webcache.h"

@interface ZHAnchorDetailTableViewCell ()

@property (nonatomic,strong) UIImageView *headImageView;
@property (nonatomic,strong) BaseLabel *title;
@property (nonatomic,strong) BaseLabel *byS;
@property (nonatomic,strong) BaseLabel *playtimes;
@property (nonatomic,strong) BaseLabel *duration;// 时长
@property (nonatomic,strong) BaseLabel *likes;
@property (nonatomic,strong) BaseLabel *comments;// 评论



@end



@implementation ZHAnchorDetailTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createView];
    }
    return self;
}
- (void)createView{
    _headImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:_headImageView];
    _title = [AppTools creatLabelWithfont:16.0f numberLine:0 textAlignment:0];
    [self.contentView addSubview:_title];
    _byS = [AppTools creatLabelWithfont:16.0f numberLine:1 textAlignment:0];
    [self.contentView addSubview:_byS];
    _playtimes = [AppTools creatLabelWithfont:14.5f numberLine:1 textAlignment:0];
    [self.contentView addSubview:_playtimes];
    _duration = [AppTools creatLabelWithfont:14.5f numberLine:1 textAlignment:0];
    [self.contentView addSubview:_duration];
    _likes = [AppTools creatLabelWithfont:14.5f numberLine:1 textAlignment:0];
    [self.contentView addSubview:_likes];
    _comments = [AppTools creatLabelWithfont:14.5f numberLine:1 textAlignment:0];
    [self.contentView addSubview:_comments];
    
    // 图片
    UIImageView *playtimesImageView = [[UIImageView alloc]init];
    playtimesImageView.image = PLACEHOLDER_IMAGE;
    [self.contentView addSubview:playtimesImageView];
    
    UIImageView *durationImageView = [[UIImageView alloc]init];
    durationImageView.image = PLACEHOLDER_IMAGE;
    [self.contentView addSubview:durationImageView];
    
    UIImageView *likesImageView = [[UIImageView alloc]init];
    likesImageView.image = PLACEHOLDER_IMAGE;
    [self.contentView addSubview:likesImageView];
    
    UIImageView *commentsImageView = [[UIImageView alloc]init];
    commentsImageView.image = PLACEHOLDER_IMAGE;
    [self.contentView addSubview:commentsImageView];
    
    [_headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.mas_equalTo(@15);
        make.width.mas_equalTo(@64);
        make.height.mas_equalTo(@64);
        
    }];
    [playtimesImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        //        make.top.equalTo(_title.mas_bottom).offset(10);
        make.left.equalTo(_headImageView.mas_right).offset(5);
        make.size.mas_equalTo(CGSizeMake(25, 25));
        make.bottom.mas_equalTo(@(-10));
    }];
    [_playtimes mas_makeConstraints:^(MASConstraintMaker *make) {
        //        make.top.equalTo(_title.mas_bottom).offset(10);
        make.left.equalTo(playtimesImageView.mas_right);
        make.size.mas_equalTo(CGSizeMake(50, 25));
        make.bottom.mas_equalTo(@(-10));
    }];
    [_byS mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_headImageView.mas_right).offset(15);
        make.right.mas_equalTo(@(-90));
        make.height.mas_equalTo(@25);
        make.bottom.equalTo(_playtimes.mas_top).offset(-5);
    }];
    [_title mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.mas_equalTo(@10);
        make.left.equalTo(_headImageView.mas_right).offset(15);
        make.right.mas_equalTo(@(-50));
        make.bottom.equalTo(_byS.mas_top).offset(-8);
    }];
    [durationImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_playtimes.mas_right);
        make.size.equalTo(playtimesImageView);
        make.bottom.mas_equalTo(@(-10));
    }];
    [_duration mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(durationImageView.mas_right);
        make.size.equalTo(_playtimes);
        make.bottom.mas_equalTo(@(-10));
    }];
    [likesImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_duration.mas_right);
        make.size.equalTo(playtimesImageView);
        make.bottom.mas_equalTo(@(-10));
    }];
    [_likes mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(likesImageView.mas_right);
        make.size.equalTo(_playtimes);
        make.bottom.mas_equalTo(@(-10));
    }];
    
    [commentsImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(_likes.mas_right);
        make.size.equalTo(playtimesImageView);
        make.bottom.mas_equalTo(@(-10));
    }];
    [_comments mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.equalTo(commentsImageView.mas_right);
        make.size.equalTo(_playtimes);
        make.bottom.mas_equalTo(@(-10));
    }];
//    _headImageView.backgroundColor = [UIColor redColor];
//   _title.backgroundColor = [UIColor greenColor];
//    _playtimes.backgroundColor = [UIColor redColor];
//    _byS.backgroundColor = [UIColor purpleColor];
//    _duration.backgroundColor = [UIColor redColor];
//    _likes.backgroundColor = [UIColor redColor];
//    _comments.backgroundColor = [UIColor redColor];

}

- (void)setModel:(ZHAnchorDetailModel *)model{
    [_headImageView sd_setImageWithURL:[NSURL URLWithString:model.coverSmall] placeholderImage:PLACEHOLDER_IMAGE];
    _title.text = model.title;
    NSInteger immm = (NSInteger)model.duration/1;
    _duration.text = [NSString stringWithFormat:@"%.02ld:%.02ld",immm/60, immm%60];
    _byS.text = [NSString stringWithFormat:@"by %@",model.nickname];
    if (model.playtimes > 9999) {
        _playtimes.text = [NSString stringWithFormat:@"%.2f万",model.playtimes/10000.0];
    }else
    _playtimes.text = [NSString stringWithFormat:@"%.2ld",model.playtimes];
    _likes.text = [NSString stringWithFormat:@"%ld",model.likes];
    _comments.text = [NSString stringWithFormat:@"%ld",model.comments];
    
    
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
